package com.ai.bitcoin.wechat.handler;

import com.ai.bitcoin.jpa.entity.BccUserBonusConfig;
import com.ai.bitcoin.jpa.service.UserBonusService;
import com.ai.bitcoin.vo.UserEncourageReq;
import com.ai.bitcoin.vo.UserEncourageResponse;
import com.ai.bitcoin.wechat.builder.TextBuilder;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SubscribeHandler extends AbstractHandler {

    @Autowired
    UserBonusService userBonusService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wechatMessage,
                                    Map<String, Object> context, WxMpService wechatService,
                                    WxSessionManager sessionManager) {

        //0101	关注奖励
        //0103	邀请关注
        UserEncourageReq request = new UserEncourageReq();

        UserEncourageResponse response = userBonusService.sendBonus(BccUserBonusConfig.EVENT_SOURCE_MP, "0101", request);
        if (CollectionUtils.isNotEmpty(response.getMessageList())) {
            return new TextBuilder().build(response.getMessageList().get(0), wechatMessage, wechatService);
        }
        return null;

    }


}
